﻿namespace _01_OOP
{
    internal class HashTableExample
    {
        class Student
        {
            public int Id { get; set; }
            public string Name { get; set; }

            public Student(int id, string name)
            {
                Id = id;
                Name = name;
            }

            public override bool Equals(object? obj)
            {
                return obj is Student student &&
                       Id == student.Id;
            }

            public override int GetHashCode()
            {
                return HashCode.Combine(Id);
            }
        }
       
        public void Test1()
        {
            var set = new HashSet<int>();
            set.Add(1);
            set.Add(1);
        }
     
        /// <summary>
        /// 如果不重新hashcode会怎样？
        /// </summary>
        public void Test2()
        {
            var set = new HashSet<Student>();
            set.Add(new Student(1, "zs"));
            set.Add(new Student(1, "zs"));
        }
    }
}
